package com.woniuxy.stage3demo.service.servicehpd.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.stage3demo.bean.hpd.ProductBean;
import com.woniuxy.stage3demo.mapper.mapperhpd.ProductMapper;
import com.woniuxy.stage3demo.pageHelper.PageRequest;
import com.woniuxy.stage3demo.service.servicehpd.IProductService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Transactional(readOnly = true)
@Service
public class ProductServiceImpl implements IProductService {
    @Resource
    private ProductMapper productMapper;

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int addProduct(ProductBean productBean) {
        return productMapper.addProduct(productBean);
    }

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int updateProduct(ProductBean productBean) {
        return productMapper.updateProduct(productBean);
    }

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int deleteProduct(Long id) {
        return productMapper.deleteProduct(id);
    }

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int batchOpt(int opt,Long id) {
        return productMapper.batchOpt(opt,id);
    }


    @Override
    public PageInfo<ProductBean> findAllByParams(PageRequest request, ProductBean productBean) {
        return PageHelper.startPage(request.getPageNum(),request.getLimit()).
                doSelectPageInfo(()->productMapper.findAllByParams(request,productBean));
    }


    @Override
    public ProductBean findOneById(Long id) {
        return productMapper.findOneById(id);
    }

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int updateStatus(ProductBean productBean) {
        return productMapper.updateStatus(productBean);
    }
}
